import View from './view';
import Form from './form';
import { validatorWrapper, getValidate } from '../utils';

import type { Rules, RuleItem } from 'async-validator/dist-types/interface';
import type { jumpPageItem } from '../../costomFields/formJumpPage/type';

export const rules: Rules = {
  // title: [
  //   {
  //     required: true,
  //     message: '标题不能为空',
  //   },
  // ],
  tplType: [
    {
      required: true,
      message: '模板不能为空',
    },
  ],
  imgRadius: [
    {
      type: 'number',
      required: true,
      message: '图片圆角不能为空',
    },
    {
      type: 'number',
      min: 0,
      message: '图片圆角不能小于0',
    },
  ],
  goodsData: [
    {
      required: true,
      message: '商品不能为空',
    },
  ],
};

export const DEFAULT_IMAGE =
  '';

export const TPL_TYPE = {
  twoLine: {
    value: 'twoLine',
    label: '两列商品',
    image: DEFAULT_IMAGE,
  },
  threeLine: {
    value: 'threeLine',
    label: '三列商品',
    image: DEFAULT_IMAGE,
  },
  oneLine: {
    value: 'oneLine',
    label: '单列商品',
    image: DEFAULT_IMAGE,
  },
  bigImg: {
    value: 'bigImg',
    label: '大图商品',
    image: DEFAULT_IMAGE,
  },
  scrollLeft: {
    value: 'scrollLeft',
    label: '左滑商品',
    image: DEFAULT_IMAGE,
  },
  oneLineAlbum: {
    value: 'oneLineAlbum',
    label: '列表商品专辑',
    image: DEFAULT_IMAGE,
  },
  threeLineAlbum: {
    value: 'threeLineAlbum',
    label: '三列商品专辑',
    image: DEFAULT_IMAGE,
  },
  scrollLeftAlbum: {
    value: 'scrollLeftAlbum',
    label: '左滑商品专辑',
    image: DEFAULT_IMAGE,
  },
};

export const GDCE_OPTION = {
  auto: {
    value: 'auto',
    label: '自动',
  },
  handAuto: {
    value: 'handAuto',
    label: '手动',
  },
};

export const SOURCE_OPTION = {
  canteenGoods: {
    value: 'canteenGoods',
    disabled: true,
    label: '点餐商品',
  },
  marketGoods: {
    value: 'marketGoods',
    label: '商城商品',
  },
};

export const BOR_STYLE = {
  whithBorder: {
    value: 'whithBorder',
    label: '有间距',
  },
  noBorder: {
    value: 'noBorder',
    label: '无间距',
  },
};

export const enumCategory = [
  {
    value: 0,
    label: '虚拟商品',
  },
  {
    value: 1,
    label: '实物商品',
    disabled: true,
  },
];

export const BG_OPTION = [
  {
    value: 1,
    label: '有背景',
  },
  {
    value: 0,
    label: '无背景',
  },
];

const initialValues = {
  title: '', // 组件标题
  titleSwitch: false, // 是否显示组件标题
  tplType: TPL_TYPE.twoLine.value, // 模板选择
  imgRadius: 0, // 图片圆角
  goodsChooseRadio: GDCE_OPTION.auto.value, // 商品选择方式
  goodsNavSwitch: false, // 是否显示商品导航
  goodsSourceRadio: SOURCE_OPTION.marketGoods.value, // 商品来源
  goodsCategory: 0, // 商品类目---0 虚拟  1实物
  goodsDisplayNum: 5, // 商品展示数量
  goodsData: [], // 商品数据
  bgType: 1,
  bgColor: '#ffffff', //背景颜色
  titleColor: '#333333', //标题颜色
  originalPriceColor: '#b9b2b2', //原价颜色
  isShowOriginal: true,
  activityPriceColor: '#fdb41a', //活动价颜色
  isShowActivity: true,
  addBtnColor: '#fdb41a', //加购按钮颜色
  isShowAddBtn: true,
  moonthSaleColor: '#cdced0', //月销量颜色
  isShowMoonthSale: true,
  boxBorder: BOR_STYLE.whithBorder.value, // 间距
  boxRadius: 5, // 圆角
  cateInfo: {
    // 商品弹窗的默认层级
    cateId: 0,
    secoundCateId: 0,
  },
  // 专辑设置
  album: [] as jumpPageItem[],
};

export type GoodsValue = typeof initialValues;

export default {
  type: 'Goods',
  title: '商品',
  logo: 'https://saascdn.yumchina.com/crmyumc/768479403501420544/member/202308211334349446.jpg',
  initialValues,
  view: View,
  form: Form,
  limit: 10,
  validate: getValidate(rules),
};
